package com.bwie.pojo;

import io.jsonwebtoken.Claims;
import io.jsonwebtoken.Jwts;
import lombok.Data;

import java.io.Serializable;
import java.util.Date;

/**
 * @projectName: server-2211a-red
 * @package: com.bwie.pojo
 * @className: BasePojo
 * @author: 杨珂
 * @description: TODO
 * @date: 2025/6/6 16:33
 * @version: 1.0
 */

@Data
public class BasePojo implements Serializable {

    /**
     * 创建人
     */
    private String createBy;

    /**
     * 创建时间
     */
    private Date createTime;

    /**
     * 更新人
     */
    private String updateBy;

    /**
     * 更新时间
     */
    private Date updateTime;

    public void readyCreate(String token) {
        if (token == null) {
            this.createBy = "未知";
        } else {
            Claims body = Jwts.parser().setSigningKey("123456").parseClaimsJws(token).getBody();
            Integer userId = body.get("userId", Integer.class);
            this.createBy = "" + userId;
        }

        this.createTime = new Date();
    }


    public void readyUpdate(String token) {
        if (token == null) {
            this.updateBy = "未知";
        } else {
            Claims body = Jwts.parser().setSigningKey("123456").parseClaimsJws(token).getBody();
            Integer userId = body.get("userId", Integer.class);
            this.updateBy = "" + userId;
        }
        this.updateTime = new Date();
    }
}
